// pages/ScenicArea/ScenicAreaCommitPage/index.js
var common = require("../../../../public.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showBuyerPanel: false,
    storeInfo: {},
    ticketOrder: '',
    orderNo: '',
    isLoading: false,
    orderobj:"",
    ticketTime:'',
    timeData: {},
    flag_fail:false,
    message: '',
    steps: [
        {
            text: '提交退款申请',
            desc: '',
          },
          {
            text: '等待商家处理',
            desc: '',
          }, 
          
      ],
    steps_two:[
        {
            text: '提交退款申请',
            desc: '',
          },
          {
            text: '退款申请通过',
            desc: '',
          }, 
          {
            text: '商家受理退款',
            desc: '',
          }, 
          {
            text: '退款成功',
            desc: '',
          }, 
    ],
    active:3,
    status:7   //模拟退款状态
  },
  onChange(event) {
    this.setData({
        message:event.detail
    })
  },
  onLoad: function (options) {
    const that = this
    console.log(options)
    wx.getStorage({
      key: 'user',
      success: function (res) {
        that.setData({
          userInfo: res.data.user,
          token: res.data.token,
          openid: res.data.openid,
          orderNo: options.orderNo,
          orderobj:options.obj
        }, () => {
          that.initData();
        })
      }
    })
  },
  initData() {
    const that = this
    let tempJson = {
      userId: that.data.userInfo.id,
      token: that.data.token,
      orderNo: that.data.orderNo,  
    }
    this.setData({
      isLoading: true
    })
    common.post('/venueOrder/getMyOrderInfo', tempJson, function (res) {
      if (res.status === 200) {
        that.setData({
          storeInfo: res.data.store,
          ticketOrder: res.data.orderInfo,
        })    
      } else {
        common.showRequestErrMsg(res)
      }
    }, function () {
      that.setData({
        isLoading: false
      })
    })
  },
  // 取消支付
  click_qv(){
    var that = this
    wx.navigateBack({
        delta: 1,
      })
  },
 
  toEticket() {
    if (this.data.ticketOrder.status == 2 || this.data.ticketOrder.status == 5) {
      wx.navigateTo({
        url: '/pages/ScenicArea/ScenicAreaETicket/index?orderNo=' + this.data.ticketOrder.orderNo,
      })
    } else {
      common.showToast('当前订单不可查看电子票')
    }
  },
  toStore() {
    const type = this.data.storeInfo.storeType == 6 ? 1 : 2
    wx.navigateTo({
      url: '/pages/ScenicArea/ScenicAreaMainPage/index?moduleType=' + type + '&id=' + this.data.storeInfo.id,
    })
  },
  makePhone() {
    wx.makePhoneCall({
      phoneNumber: this.data.storeInfo.mobile,
    })
  },
  goback() {
    wx.navigateBack({
      delta: 1,
    })
  },
  refund() {
    const that = this
    common.showAlertView('提示', '您确定要申请退款吗？', function (sure) {
      if (sure) {
        const param = {
          orderNo: that.data.ticketOrder.orderNo,
          refundAmount:that.data.ticketOrder.payment,
          refundReason: that.data.message,
          userId: that.data.userInfo.id,
          token: that.data.token,
        }
        common.post('/venueOrder/refundTVenueOrder', param, function (res) {
          if (res.status === 200) {
            const pages = getCurrentPages()
            const prePage = pages[pages.length - 2]
            wx.navigateBack({
              delta: 1,
              success: function () {
                common.showToast('退款申请发送成功')
                if (prePage && prePage.reloadData) {
                  prePage.reloadData()
                }
              }
            })
          } else {
            common.showRequestErrMsg(res)
          }
        })
      }
    })
  }
})